package 测试;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {
    public static void main(String[] args) {
        //创建线程池对象，参数5，代表有5个线程的线程池
        ExecutorService service = Executors.newFixedThreadPool(4);
        //创建Runnable线程任务对象
        TaskRunnable task=new TaskRunnable();
        //从线程池获取线程对象

        service.submit(task);

        //再获取一个线程对象
        service.submit(task);
        //关闭线程
        service.shutdown();

    }

}
 class TaskRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread()+"开始执行-------------");
        for (int i=0;i<10;i++)
        {
            System.out.println("自定义线程任务正在执行--"+i);
        }
    }
}